﻿using System.Collections.Generic;
using System.Threading.Tasks;

namespace Sidvall.Logging.Diagnostics
{
    public class Log : Sidvall.Logging.LogBase
    {
        #region Public Members

        #region WriteAsync

        public override Task WriteAsync(string title, string message, IEnumerable<string> categories, EventType severity, IDictionary<string, string> properties)
        {
            if (!this.ShouldLog(categories, severity))
                return Task.FromResult(true);
            if (!string.IsNullOrWhiteSpace(title))
                message = title + ": " + message;
            switch (severity)
            {
                case EventType.Critical:
                case EventType.Error:
                    System.Diagnostics.Trace.TraceError(message);
                    break;
                case EventType.Warning:
                    System.Diagnostics.Trace.TraceWarning(message);
                    break;
                case EventType.Information:
                    System.Diagnostics.Trace.TraceInformation(message);
                    break;
                default:
                    throw new System.ArgumentException(nameof(severity));
            }
            return Task.FromResult(true);
        }

        #endregion
        #region ToString

        public override string ToString()
        {
            return "Log - Diagnostics";
        }

        #endregion

        #endregion
        #region Constructors

        public Log()
        {
        }

        #endregion
    }
}
